$(document.body).on('click', '.dropdown-menu-select li', function(event) {
	var $target = $(event.currentTarget);
	$target.closest('.btn-group').find('[data-bind="label"]').text($target.text()).end().children('input').val($target.attr('value')).end().children('.dropdown-toggle').dropdown('toggle');
	return false;
});

WEBAPP['pageDict'] = function() {
	$('#dictForm').submit(function() {
		var word = $('#word').val().trim();
		if (!word) {
			$('#word').focus();
			return false;
		}
		
		if (word.indexOf(' ') > 0) {
			$('#word').val('');
			
			$('#str').val(word);
			$('#transForm').submit();
			
			$('#tabTransLink').tab('show');
			
			return false;
		}

		$.getJSON('http://m.vdict.com/mobile/dictjson?fromapp=1&callback=?', {
			dict : $('#dict').val(),
			word : word
		}, function(data) {
			if (data) {
				console.log('type', data.type);
				var html = data.result;
				html = html.replace(/style="text-align:center"/, 'class="dict-rs-head"');
				$('#dictRs').html(html);
			}

		});

		return false;
	});

	window['evtrancb'] = function(data) {
		if (data) {
			$('#transRs').html(data['result']);
		}
	};

	$('#transForm').submit(function() {
		var str = $('#str').val().trim();
		if (!str) {
			$('#str').focus();
			return false;
		}

		$.ajax({
			url : 'http://app.vdict.com/api.php',
			dataType : 'jsonp',
			jsonpCallback : 'evtrancb',
			data : {
				str : str
			},
			cache : true
		});

		return false;
	});
};